package com.wpml.product.controller;

import com.wpml.common.util.PageUtils;
import com.wpml.common.util.ResultJson;
import com.wpml.product.entity.SkuInfoModel;
import com.wpml.product.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * sku信息
 *
 * @author leifengyang
 * @email leifengyang@gmail.com
 * @date 2019-10-01 22:50:32
 */
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("product:skuinfo:list")
    public ResultJson list(@RequestParam Map<String, Object> params){
        PageUtils page = skuInfoService.queryPageByCondition(params);

        return ResultJson.ok(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{skuId}")
    //@RequiresPermissions("product:skuinfo:info")
    public ResultJson info(@PathVariable("skuId") Long skuId){
		SkuInfoModel skuInfo = skuInfoService.getById(skuId);

        return ResultJson.ok(skuInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("product:skuinfo:save")
    public ResultJson save(@RequestBody SkuInfoModel skuInfo){
		skuInfoService.save(skuInfo);

        return ResultJson.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("product:skuinfo:update")
    public ResultJson update(@RequestBody SkuInfoModel skuInfo){
		skuInfoService.updateById(skuInfo);

        return ResultJson.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("product:skuinfo:delete")
    public ResultJson delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return ResultJson.ok();
    }

}
